package ch.unisi.inf.editor;

import javax.swing.AbstractAction;
import java.awt.event.*;
import javax.swing.ImageIcon;
import java.awt.event.*;
import javax.swing.*;

import ch.unisi.inf.engine.Image;

/**
 * creates a command to save an image
 * 
 * @author matthias.eberli@lu.unisi.ch
 */
public class SaveImgCommand extends AbstractAction
{
  private final Image image;
  private final EditorButtonFrame editorButtonFrame;
  private final ImagePanel imagePanel;
    
    
    public SaveImgCommand(final Image image, final EditorButtonFrame editorButtonFrame, final ImagePanel imagePanel) 
    {
        this.image = image;
        this.editorButtonFrame = editorButtonFrame;
        this.imagePanel = imagePanel;
        // menu item text
        putValue(NAME, "Save");
        // used as accelerator (underlined in text, allow user to press this key to select this action)
        putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.ALT_DOWN_MASK));
        // tooltip text
        putValue(SHORT_DESCRIPTION, "Save the changes");

        
        
        editorButtonFrame.addEditorButtonFrameListener(new EditorButtonFrameListener() {
            public void imageCharged() {
                setEnabled(imagePanel.hasImage());
            }
        });
    }
    
    public void actionPerformed(final ActionEvent ev) 
    {
        imagePanel.saveAs();
    }
}
